package at.fhj.swd.pse.gui.drivers;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

/**
 * 
 * Use this base class to perform gui tests with selenium.
 * 
 * @author Robert Angerer
 * 
 */

public class GuiTestBaseSeleniumJava4Webdriver {
	private WebDriver driver;
	private String baseUrl;
	private StringBuffer verificationErrors = new StringBuffer();

	public void start() throws Exception {
		this.driver = new FirefoxDriver();
		this.baseUrl = "http://localhost:8080/SWDPortal/";
		this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	public void startSpecific(final WebDriver driver, final String baseUrl, final int timeoutInSeconds) throws Exception {
		this.setDriver(driver);
		this.setBaseUrl(baseUrl);
		this.driver.manage().timeouts().implicitlyWait(timeoutInSeconds, TimeUnit.SECONDS);
		/*
		 * this.driver = new FirefoxDriver(); this.baseUrl =
		 * "http://localhost:8080/SWDPortal/";
		 * this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		 */
	}

	public void end() throws Exception {
		this.driver.quit();
		String verificationErrorString = this.verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	public WebDriver getDriver() {
		return this.driver;
	}

	public void setDriver(final WebDriver driver) {
		this.driver = driver;
	}

	public String getBaseUrl() {
		return this.baseUrl;
	}

	public void setBaseUrl(final String baseUrl) {
		this.baseUrl = baseUrl;
	}

	public StringBuffer getVerificationErrors() {
		return this.verificationErrors;
	}

	public void setVerificationErrors(final StringBuffer verificationErrors) {
		this.verificationErrors = verificationErrors;
	}
}
